﻿
using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.FarmingInformation
{
    public class BreedingcompanyphotoHander : IRequestHandler<BreedingcompanyphotoCommond, Rulst>
    {

        private readonly IbaseRpository<ProductionPutImages> _ProductionPutImages;

        public BreedingcompanyphotoHander(IbaseRpository<ProductionPutImages> productionPutImages)
        {
            _ProductionPutImages = productionPutImages;
        }

        public async Task<Rulst>  Handle(BreedingcompanyphotoCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };

            var result = _ProductionPutImages.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid && x.Stypeid == Typenum.企业照片).ToList();
            if(result==null||result.Count<6)
            {
                var list = new ProductionPutImages()
                {

                    Stypeid = Typenum.企业照片
              ,
                    ProDuctionBasicid = request.ProDuctionBasicid,
                    PutImages = request.imgess,
                    Putid = 0
                };



                query.data = _ProductionPutImages.Add(list);
            }
            else
            {
                if (result.Count == 6 && result != null)
                {

                    query.data = -7;
                }

            }

            



            return query;
        }
    }
}
